package {
	import flash.display.Sprite;
	import flash.events.Event;
	
	import org.libra.JButton;
	import org.libra.JFrame;
	import org.libra.JPageCounter;
	import org.libra.JTextField;
	import org.libra.JWindow;
	import org.libra.events.LibraEvent;
	import org.libra.geom.IntDimension;
	import org.libra.geom.IntPoint;
	import org.libra.managers.LibraManager;
	
	/**
	 * 
	 */
	public class Main extends Sprite {
		
		private var textField:JTextField;
		private var count:int;
		
		public function Main():void {
			if (stage) 
				init();
			else 
				addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void {
			
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point
			//初始化LibraUI的大管家LibraManager
			LibraManager.getInstance(this);
			
			//所有的组件都在面板上，所有的面板都在窗口中
			var win:JWindow = new JWindow(this);
			win.setSize(new IntDimension(stage.stageWidth, stage.stageHeight));
			win.show();
			
			//new一个面板
			var frame:JFrame = new JFrame(win);
			frame.setSize(new IntDimension(300, 400));
			frame.setLocation(new IntPoint((win.getWidth() - frame.getWidth()) >> 1, (win.getHeight() - frame.getHeight()) >> 1));
			frame.show();
			
			var btn:JButton = new JButton("我是按钮");
			btn.setSize(new IntDimension(64, 23));
			btn.setLocation(new IntPoint(100, 100));
			btn.addActionListener(onBtnHandler);
			frame.append(btn);
			
			textField = new JTextField();
			textField.setSize(new IntDimension(100, 23));
			textField.setLocation(new IntPoint(5, 30));
			frame.append(textField);
		}
		
		private function onBtnHandler(evt:LibraEvent):void {
			count += 1;
			textField.setText("按钮被点击了" + count + "次");
		}
		
	}
	
}